//
//  API_KVO_Demo1VC.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/6/28.
//

import UIKit
import Foundation

class KVO_Person: NSObject {
    @objc dynamic var age: Int = 0

}

class API_KVO_Demo1VC: UIViewController {

    @objc dynamic let p = KVO_Person()
    var ob: NSKeyValueObservation?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        ob = observe(\.p.age, options: [.new, .old], changeHandler: { (_, change) in
            print(change as Any)
        })
        
        p.age = 30
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        p.age = 60
    }

}
